/*
 *  Copyright 2019-2020 Zheng Jie
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package cc.sheji.domain;

import cc.sheji.annotation.Query;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
* @author Zheng Jie
* @date 2019-6-4 14:49:34
*/
@Data
@ToString
@NoArgsConstructor
public class NoticeQueryCriteria {

    @Query
    public Long userId;
    @Query
    public Integer type;
    @Query
    public Integer name;
    @Query
    public Integer deleted=0;


    @Query(type = Query.Type.BETWEEN)
    private List<Date> createTime;

    private String startDate;

    private String endDate;


    public void setStartDate(String startDate) {
        this.startDate = startDate;
        this.setCreateTime(null);
    }

    public void setEndDate(String endDate) {
        this.endDate = endDate;
        this.setCreateTime(null);
    }

    public void setCreateTime(List<Date> createTime)  {
        this.createTime = createTime;

        System.out.println("setCeateTime");
        List<Date> list = new ArrayList<>();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        Date date1= new Date();
        //  date1.setYear(1000);
        try {
            date1 = simpleDateFormat.parse(startDate);
        } catch (Exception e) {
            try {
                date1 = simpleDateFormat.parse("2000-01-01 00:00:00");
            }catch (Exception exception){

            }

            // e.printStackTrace();
        }
        Date date2 = new Date();
        try {
            date2 = simpleDateFormat.parse(endDate);
        } catch (Exception e) {
            // e.printStackTrace();
        }
        list.add(date1);
        list.add(date2);
        this.createTime=list;
    }

    public List<Date> getCreateTime() {
        System.out.println("getCeateTime");
        List<Date> list = new ArrayList<>();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        Date date1= new Date();
        try {
            date1 = simpleDateFormat.parse(startDate);
        } catch (Exception e) {
            try {
                date1 = simpleDateFormat.parse("2000-01-01 00:00:00");
            }catch (Exception exception){

            }
            //e.printStackTrace();
        }
        Date date2 = new Date();
        try {
            date2 = simpleDateFormat.parse(endDate);
        } catch (Exception e) {
            // e.printStackTrace();
        }
        list.add(date1);
        list.add(date2);
        return list;
    }





}